﻿/// <reference path="../PopupWin/MyPopupWin.js" />
/// <reference path="../../My/JQExtend.js" />
/// <reference path="../../../MyJS/MyDatetime.js" />

//日期选择框
var DateTimePanel = {
    //标志日期选择框是否进行了初始化
    //内置的枚举值
    enums: {
        //面板显示类型定义
        PT: {
            PT_YEAR: "year",
            PT_MON: "month",
            PT_DAY: "day",
            PT_HOUR: "hour",
            PT_MINU: "minute",
            PT_SEC: "second"
        },
        //日期框的日期数据类型
        dateType: {
            month: 'yyyy-MM', //显示年月：yyyy-mm
            date: 'yyyy-MM-dd', //显示日期：yyyy-mm-dd
            minute: 'yyyy-MM-dd HH:mm', //显示到分钟
            second: 'yyyy-MM-dd HH:mm:ss' //显示到秒
        }
    },
    data: {
        curPT: 'day', //默认显示天的面板
        curDateType: 'yyyy-MM',
        //当前选中的日期
        curSelDate: new Date(),
        //当前设置日期的域
        curEl: null,
        //原选择的Part项
        lastPart: null,
        //原突起的按钮样式的对象
        lastButton: null,
        //日期选择框的显示高度
        panelHeight: 270,
        contentHeight: 206,//内容的高度
        //点击年后的偏移
        yearOffset: 0
    },
    initialized: false,
    //弹出框
    popuWin: null
};

DateTimePanel.init = function () {
    /// <summary>初始化日期选择框</summary>
    if (this.initialized) return;
    this.initialized = true;
    //执行初始化的操作
    this.popuWin = window.createPopup();
    this.initHtml();
};

DateTimePanel.setDateTimeEl = function (el, bBindClickFunc) {
    /// <summary>日期选择框绑定元素</summary>    
    /// <param name="el" type="DOMElement/String[id]">dom元素对象或者是元素的ID号</param>
    /// <param name="bBindClickFunc" type="Boolean">是否绑定输入框的单击然后显示日期控件的事件</param>
    el = $.getJQObj(el);
    if (el === null) return;
    var bValidate = false;
    var dateType = 'yyyy-MM-dd';
    //查看输入框的dataType属性
    if (el[0].dateType) {
        dateType = el[0].dateType
    }
    else {
        el[0].dateType = dateType;
    }
    var types = this.enums.dateType;
    //验证输入的dateType是否合法
    for (var type in types) {
        if (dateType === this.enums.dateType[type]) {
            bValidate = true;
            break;
        }
    }
    if (!bValidate) return;
    if (bBindClickFunc) {
        el.click({ o: this }, function (e) {
            DateTimePanel.show(e.currentTarget);
        });
    }
};

DateTimePanel.show = function (el) {
    /// <summary>在指定的input元素上面显示日期控件</summary>
    /// <param name="el" type="DOMElement/String[id]">dom元素对象或者是元素的ID号</param>
    var obj = $.getJQObj(el);
    if (obj === null) return;
    if (!this.initialized) this.init();
    this.data.curEl = obj[0];
    this.data.curDateType = obj[0].dateType; //从input对象那里取得dateType属性
    this.data.curSelDate = MyDatetime.createDateObj(obj[0].value, this.data.curDateType);
    var curType = this.data.curDateType;
    //当前面板只显示月份
    if (curType === this.enums.dateType.month) {
        this.data.curPT = this.enums.PT.PT_MON;
        this.data.panelHeight = 210;
        this.data.contentHeight = 140;
    }
    else if (curType === this.enums.dateType.second) {
        this.data.curPT = this.enums.PT.PT_DAY;
        this.data.panelHeight = 290;
        this.data.contentHeight = 206;
    }
    else if (curType === this.enums.dateType.date) {
        this.data.curPT = this.enums.PT.PT_DAY;
        this.data.panelHeight = 270;
        this.data.contentHeight = 206;
    }
    this.updatePanel();
    this.popuWin.show(0, obj[0].offsetHeight, 304, this.data.panelHeight, obj[0]);
};

DateTimePanel.hide = function () {
    if (this.popuWin) {
        this.popuWin.hide();
        this.data.curEl = null;
    }
};

DateTimePanel.initHtml = function () {
    /// <summary>获取日期框的初始化HTML</summary>
    var oBody = this.popuWin.document.body;
    oBody.style.border = "1px solid #D0D0D0";
    oBody.style.backgroundColor = "#52A3E2";
    var dtToday = new Date();
    var sHtml = "<table style='border:0;width:100%;margin-top:4px;'>";
    var curDateType = this.data.curDateType;
    sHtml += DateTimePanel.htmlTemplate.yyyyMMddHeader + DateTimePanel.htmlTemplate.HHmmssHeader;
    sHtml += "<tr><td id='Panel' style='width:100%;height:206px;margin:0;padding:0;'></td></tr>" +
 	         "<tr><td id='Panel2' style='width:100%;height:20px;padding-left:14px;'>" +
 	         "<a href='#' onclick='parent.DateTimePanel.panelToday()' style='font-size:10pt;color:#035A13;font-weight:bold;border:1 solid #52A3E2;' bcr='#52A3E2' title='" + dtToday.getFullYear() + "-" + (dtToday.getMonth() + 1) + "-" + dtToday.getDate() + "' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>[今 天]</a>　" +
 	         "<a href='#' onclick='parent.DateTimePanel.panelOk()' style='font-size:10pt;color:#ffffff;font-weight:bold;border:1 solid #52A3E2;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>[确 定]</a>　" +
 	         "<a href='#' onclick='parent.DateTimePanel.panelClear()' style='font-size:10pt;color:#ffffff;font-weight:bold;border:1 solid #52A3E2;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>[清 空]</a>　" +
 	         "<a href='#' onclick='parent.DateTimePanel.panelClose()' style='font-size:10pt;color:#ffffff;font-weight:bold;border:1 solid #52A3E2;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>[取 消]</a>" +
 	         "</td></tr></table>";
    oBody.innerHTML = sHtml;
};

/************************************日历操作函数********************************/
//点击项目内容
DateTimePanel.partClick = function (sType) {
    this.data.curPT = sType;
    this.data.yearOffset = 0;
    this.updatePanel();
};

DateTimePanel.hilightObj = function (oButton, bIn) {
    /// <summary>高亮选中某个对象</summary>
    if (this.data.lastButton != null && this.data.lastButton != oButton) {
        if (this.data.lastButton.bcr) {
            this.data.lastButton.style.borderWidth = "1";
            this.data.lastButton.style.borderStyle = "solid";
            this.data.lastButton.style.borderColor = this.data.lastButton.bcr;
        } else {
            this.data.lastButton.style.borderWidth = "0";
            this.data.lastButton.style.borderStyle = "";
            this.data.lastButton.style.borderColor = "";
        }
    }
    if (bIn) {
        this.data.lastButton = oButton;
        if (this.data.lastButton != null) {
            this.data.lastButton.style.borderWidth = "1";
            this.data.lastButton.style.borderStyle = "solid";
            this.data.lastButton.style.borderColor = "#FFFFFF #808080 #808080 #FFFFFF";
        }
    } else {
        if (oButton != null) {
            if (this.data.lastButton.bcr) { //保留边框
                this.data.lastButton.style.borderWidth = "1";
                this.data.lastButton.style.borderStyle = "solid";
                this.data.lastButton.style.borderColor = this.data.lastButton.bcr;
            } else {
                this.data.lastButton.style.borderWidth = "0";
                this.data.lastButton.style.borderStyle = "";
                this.data.lastButton.style.borderColor = "";
            }
        }
        this.data.lastButton = null;
    }
};

//点击项目左
//bLeft,true向前一个范围，false向后一个范围
DateTimePanel.partArraw = function (sType, bLeft) {
    var curSelDate = this.data.curSelDate;
    var iSel;
    if (sType === this.enums.PT.PT_YEAR) {
        iSel = curSelDate.getFullYear();
        if (bLeft) iSel--;
        else iSel++;
        curSelDate.setFullYear(iSel);
    }
    else if (sType == this.enums.PT.PT_MON) {
        iSel = curSelDate.getMonth();
        if (bLeft) iSel--;
        else iSel++;
        curSelDate.setMonth(iSel);
    }
    else if (sType == this.enums.PT.PT_DAY) {
        iSel = curSelDate.getDate();
        if (bLeft) iSel--;
        else iSel++;
        curSelDate.setDate(iSel);
    }
    else if (sType == this.enums.PT.PT_HOUR) {
        iSel = curSelDate.getHours();
        if (bLeft) iSel--;
        else iSel++;
        curSelDate.setHours(iSel);
    }
    else if (sType == this.enums.PT.PT_MINU) {
        iSel = this.data.curSelDate.getMinutes();
        if (bLeft) iSel--;
        else iSel++;
        this.data.curSelDate.setMinutes(iSel);
    }
    else if (sType == this.enums.PT.PT_SEC) {
        iSel = curSelDate.getSeconds();
        if (bLeft) iSel--;
        else iSel++;
        curSelDate.setSeconds(iSel);
    }
    this.updatePanel();
};

DateTimePanel.updatePanel = function () {
    var dtToday = new Date();
    var curType = this.data.curDateType;
    var sVal = "";

    //更新年月日的数字
    sVal = this.data.curSelDate.getMonth() + 1;
    if (sVal < 10) sVal = "0" + sVal;
    this.popuWin.document.all.PartM.innerText = sVal + "月";
    sVal = this.data.curSelDate.getDate();
    if (sVal < 10) sVal = "0" + sVal;
    this.popuWin.document.all.PartD.innerText = sVal + "日";
    sVal = this.data.curSelDate.getFullYear();
    this.popuWin.document.all.PartY.innerText = sVal + "年";

    //根据是否只显示月份的情况下，隐藏日的选择
    var showStype = curType === this.enums.dateType.month ? "none" : "";
    var aHide = ['PartD_L', 'PartD', 'PartD_R'];
    for (var i = 0; i < aHide.length; i++) {
        this.popuWin.document.getElementById(aHide[i]).style.display = showStype;
    }

    if (curType === this.enums.dateType.second) {
        this.popuWin.document.getElementById("PartTime").style.display = "";
        sVal = this.data.curSelDate.getHours();
        if (sVal < 10) sVal = "0" + sVal;
        this.popuWin.document.all.PartH.innerText = sVal + "时";
        sVal = this.data.curSelDate.getMinutes();
        if (sVal < 10) sVal = "0" + sVal;
        this.popuWin.document.all.PartN.innerText = sVal + "分";
        sVal = this.data.curSelDate.getSeconds();
        if (sVal < 10) sVal = "0" + sVal;
        this.popuWin.document.all.PartS.innerText = sVal + "秒";
    }
    else {
        this.popuWin.document.getElementById("PartTime").style.display = "none";
    }

    var oPanel = this.popuWin.document.all.Panel;
    if (this.data.lastPart != null) {
        this.data.lastPart.style.backgroundColor = "";
    }
    var iCur, iCurY, iToday, ixp, iyp;
    var sHtml, sExp, sSel;
    if (this.data.curPT == this.enums.PT.PT_YEAR) {
        this.data.lastPart = this.popuWin.document.all.PartY;
        iCur = this.data.curSelDate.getFullYear();
        iToday = dtToday.getFullYear();
        sVal = iCur - (iCur % 5) - 25 + this.data.yearOffset;
        if (sVal < 0) sVal = 0;
        sHtml = "<table style='width:100%;border:1px solid white;font-size:9pt;'>";
        for (ixp = 0; ixp < 8; ixp++) {
            sHtml += "<tr style='height:20px;' bgcolor='#EFEFEF' valign='middle' align='center'>";
            if (ixp == 0) {
                sHtml += "<td bgcolor='#CCCCCC' bcr='#CCCCCC' style='border:1 solid #CCCCCC;color:red;width:5%;font-family:Marlett;font-size:12pt;cursor:hand;' onclick='parent.Panel_Year(true)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>5</td>";
            }
            else if (ixp == 7) {
                sHtml += "<td bgcolor='#CCCCCC' bcr='#CCCCCC' style='border:1 solid #CCCCCC;color:red;font-family:Marlett;font-size:12pt;cursor:hand;' onclick='parent.Panel_Year(false)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>6</td>";
            }
            else if (ixp == 1) {
                sHtml += "<td rowSpan=6>&nbsp;</td>";
            }
            for (iyp = 0; iyp < 5; iyp++) {
                if (iCur == sVal) sSel = "background-color:#FF0000;color:#FFFFFF;";
                else if (iToday == sVal) sSel = "background-color:#45D045;";
                else sSel = "";
                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\",0)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='#EFEFEF' style='border:1 solid #EFEFEF;cursor:hand;" + sSel + (ixp == 0 ? "width:19%;" : "") + "'>" + sVal + "</td>";
                sVal++;
            }
            sHtml += "</tr>";
        }
    }
    else if (this.data.curPT == this.enums.PT.PT_MON) {
        this.data.lastPart = this.popuWin.document.all.PartM;

        iCur = this.data.curSelDate.getMonth() + 1;
        iToday = dtToday.getMonth() + 1;
        sVal = 1;
        sHtml = "<table style='width:100%;height:50%;border:1px solid white;margin-top:20px;'>";
        iCurY = this.data.curSelDate.getFullYear();
        for (ixp = 0; ixp < 2; ixp++) {
            sHtml += "<tr style='height:26px;' bgcolor='#EFEFEF' valign='middle' align='center'>";
            for (iyp = 0; iyp < 6; iyp++) {
                if (iCur == sVal) sSel = "background-color:#FF0000;color:#FFFFFF;";
                else if (iCurY == dtToday.getFullYear() && iToday == sVal) sSel = "background-color:#45D045;";
                else sSel = "";
                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\",0)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='#EFEFEF' style='border:1 solid #EFEFEF;cursor:hand;" + sSel + (ixp == 0 ? "width:16%;" : "") + "'>" + sVal + "<font color='#A0A0A0'>月</font></td>";
                sVal++;
            }
            sHtml += "</tr>";
            if (ixp == 0) sHtml += "<tr><td colspan=6 style='height:50px;background-color:#CCCCCC;'>&nbsp;</td></tr>";
        }
    }
    else if (this.data.curPT == this.enums.PT.PT_DAY) {
        this.data.lastPart = this.popuWin.document.all.PartD;

        var iWeek, iSign;
        iCurY = this.data.curSelDate.getMonth();
        iCur = this.data.curSelDate.getDate();
        iToday = dtToday.getDate();

        var dtFirst = new Date(this.data.curSelDate.getFullYear(), this.data.curSelDate.getMonth(), 1);
        iWeek = dtFirst.getDay();
        dtFirst.setDate(1 - iWeek);
        sHtml = "<table style='width:100%;border:1px solid white;'>" +
		"<tr style='font-size:9pt;height:18px;font-weight:bold;' bgcolor='#CCCCCC' valign='middle' align='center'><td style='width:14.29%;'>日</td><td style='width:14.29%;'>一</td><td style='width:14.29%;'>二</td><td style='width:14.29%;'>三</td><td style='width:14.29%;'>四</td><td style='width:14.29%;'>五</td><td style='width:14.29%;'>六</td></tr>";
        for (ixp = 0; ixp < 6; ixp++) {
            sHtml += "<tr style='font-size:10pt;height:18px;' bgcolor='#EFEFEF' valign='middle' align='center'>";
            for (iyp = 0; iyp < 7; iyp++) {
                sVal = dtFirst.getDate();
                if (iCurY != dtFirst.getMonth()) {
                    if (iyp == 0 || iyp == 6) sExp = "color:#FFAAAA;";
                    else sExp = "color:#CCCCCC";
                }
                else if (iyp == 0 || iyp == 6) {
                    sExp = "color:#FF2020;";
                }
                else {
                    sExp = "";
                }
                if (iCurY == dtFirst.getMonth() && iCur == sVal) {
                    sSel = "background-color:#FF0000;color:#FFFFFF;";
                    sExp = "";
                }
                else if (dtFirst.getMonth() == dtToday.getMonth() && iToday == sVal) {
                    sSel = "background-color:#45D045;";
                }
                else {
                    sSel = "";
                }
                iSign = 0;
                if (iCurY != dtFirst.getMonth()) {
                    if (iCurY == 11 && dtFirst.getMonth() == 0) iSign = 1;
                    else if (iCurY == 0 && dtFirst.getMonth() == 11) iSign = -1;
                    else if (dtFirst.getMonth() > iCurY) iSign = 1;
                    else if (dtFirst.getMonth() < iCurY) iSign = -1;
                }
                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\"," + iSign + ")' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='#EFEFEF' style='border:1 solid #EFEFEF;cursor:hand;" + sSel + sExp + "'>" + sVal + "</td>";
                dtFirst.setDate(sVal + 1);
            }
        }
    }
    else if (this.data.curPT == this.enums.PT.PT_HOUR) {
        this.data.lastPart = this.popuWin.document.all.PartH;
        iCur = this.data.curSelDate.getHours();
        iToday = dtToday.getHours();
        sVal = 0;
        sHtml = "<table style='width:100%;border:1px solid white;font-size:10pt;'>";
        for (ixp = 0; ixp < 6; ixp++) {
            if (ixp > 2) sExp = "#D8D8D8";
            else sExp = "#EFEFEF";
            sHtml += "<tr style='height:26px;' bgcolor='" + sExp + "' valign='middle' align='center'>";
            for (iyp = 0; iyp < 4; iyp++) {
                if (iCur == sVal) sSel = "background-color:#FF0000;color:#FFFFFF;";
                else if (iToday == sVal) sSel = "background-color:#45D045;";
                else sSel = "";

                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\",0)'' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='" + sExp + "' style='border:1 solid " + sExp + ";cursor:hand;" + sSel + (ixp == 0 ? "width:25%;" : "") + "'>" + (sVal < 10 ? "0" : "") + sVal + "<font color='#A0A0A0'>时</font></td>";
                sVal++;
            }
        }
    }
    else if (this.data.curPT == this.enums.PT.PT_MINU) {
        this.data.lastPart = this.popuWin.document.all.PartN;
        iCur = this.data.curSelDate.getMinutes();
        iToday = dtToday.getMinutes();
        sVal = 0;
        sHtml = "<table style='width:100%;border:1px solid white;font-size:10pt;'>";
        for (ixp = 0; ixp < 6; ixp++) {
            sHtml += "<tr style='height:26px;' bgcolor='#EFEFEF' valign='middle' align='center'>";
            for (iyp = 0; iyp < 3; iyp++) {
                if (iCur == sVal) sSel = "background-color:#FF0000;color:#FFFFFF;";
                else if (iToday == sVal) sSel = "background-color:#45D045;";
                else sSel = "";
                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\",0)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='#EFEFEF' style='border:1 solid #EFEFEF;cursor:hand;" + sSel + (ixp == 0 ? "width:33.3%;" : "") + "'>" + (sVal < 10 ? "0" : "") + sVal + "<font color='#A0A0A0'>分</font></td>";
                if (iyp == 0) sVal += 5;
                else if (iyp == 1) sVal += 4;
                else sVal += 1;
            }
        }
    }
    else if (this.data.curPT == this.enums.PT.PT_SEC) {
        this.data.lastPart = this.popuWin.document.all.PartS;
        iCur = this.data.curSelDate.getSeconds();
        iToday = dtToday.getSeconds();
        sVal = 0;
        sHtml = "<table style='width:100%;border:1px solid white;font-size:10pt;'>";
        for (ixp = 0; ixp < 6; ixp++) {
            sHtml += "<tr style='height:26px;' bgcolor='#EFEFEF' valign='middle' align='center'>";
            for (iyp = 0; iyp < 3; iyp++) {
                if (iCur == sVal) sSel = "background-color:#FF0000;color:#FFFFFF;";
                else if (iToday == sVal) sSel = "background-color:#45D045;";
                else sSel = "";

                sHtml += "<td onclick='parent.DateTimePanel.panelClick(" + sVal + ",\"" + this.data.curPT + "\",0)' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)' bcr='#EFEFEF' style='border:1 solid #EFEFEF;cursor:hand;" + sSel + (ixp == 0 ? "width:33.3%;" : "") + "'>" + (sVal < 10 ? "0" : "") + sVal + "<font color='#A0A0A0'>秒</font></td>";
                if (iyp == 0) sVal += 5;
                else if (iyp == 1) sVal += 4;
                else sVal += 1;
            }
        }
    }
    sHtml += "</table>";
    oPanel.innerHTML = sHtml;
    oPanel.style.height = this.data.contentHeight + "px";
    if (this.data.lastPart != null) {
        this.data.lastPart.style.backgroundColor = "#FF0000";
    }
};

//点击面板内容
//iSign==-1表示是早一个范围
//     ==0表示是当前范围
//     ==1表示是晚一个范围
DateTimePanel.panelClick = function (sVal, sType, iSign) {
    var iSel = parseInt(sVal);
    var curType = this.data.curDateType; //当前的数据格式
    if (iSel < 0) iSel = 0;
    var iTemp;
    if (sType === this.enums.PT.PT_YEAR) {
        this.data.curSelDate.setFullYear(iSel);
        //下一个面板就显示月份了
        this.data.curPT = this.enums.PT.PT_MON;
    }
    else if (sType === this.enums.PT.PT_MON) {
        if (iSign != 0) {
            iTemp = this.data.curSelDate.getFullYear();
            if (iSign < 0) iTemp--;
            else if (iSign > 0) iTemp++;
            this.data.curSelDate.setFullYear(iTemp);
        }
        this.data.curSelDate.setMonth(iSel - 1);
        if (curType === this.enums.dateType.month) {
            this.panelOk();
            return;
        }
        else {
            this.data.curPT = this.enums.PT.PT_DAY;
        }
    }
    else if (sType == this.enums.PT.PT_DAY) {
        if (iSign != 0) {
            iTemp = this.data.curSelDate.getMonth();
            if (iSign < 0) iTemp--;
            else if (iSign > 0) iTemp++;
            this.data.curSelDate.setMonth(iTemp);
        }
        this.data.curSelDate.setDate(iSel);
        //如果是选择yyyy-MM-dd的话，则直接返回就行了
        if (curType === this.enums.dateType.date) {
            this.panelOk();
            return;
        }
        else {
            this.data.curPT = this.enums.PT.PT_HOUR;
        }
    }
    else if (sType == this.enums.PT.PT_HOUR) {
        if (iSign != 0) {
            iTemp = this.data.curSelDate.getDate();
            if (iSign < 0) iTemp--;
            else if (iSign > 0) iTemp++;
            this.data.curSelDate.setDate(iTemp);
        }
        this.data.curSelDate.setHours(iSel);
        this.data.curPT = this.enums.PT.PT_MINU;
    }
    else if (sType == this.enums.PT.PT_MINU) {
        if (iSign != 0) {
            iTemp = this.data.curSelDate.getHours();
            if (iSign < 0) iTemp--;
            else if (iSign > 0) iTemp++;
            this.data.curSelDate.setHours(iTemp);
        }
        this.data.curSelDate.setMinutes(iSel);
        this.data.curPT = this.enums.PT.PT_SEC;
    }
    else if (sType == this.enums.PT.PT_SEC) {
        if (iSign != 0) {
            iTemp = this.data.curSelDate.getMinutes();
            if (iSign < 0) iTemp--;
            else if (iSign > 0) iTemp++;
            this.data.curSelDate.setMinutes(iTemp);
        }
        this.data.curSelDate.setSeconds(iSel);
        this.panelOk();
        return;
    }
    this.updatePanel();
};

//点击清空
DateTimePanel.panelClear = function () {
    var el = this.data.curEl;
    if (el != null) {
        el.value = "";
        el.focus();
    }
    this.hide();
};

//点击确定
DateTimePanel.panelOk = function () {
    var el = this.data.curEl;
    var curType = this.data.curDateType;
    if (el != null) {
        var dtToday = this.data.curSelDate;
        var sDate = "";
        var iVal = "";

        //拼凑年月份
        var iYear = dtToday.getFullYear();
        var iMonth = dtToday.getMonth() + 1;
        var iDay = dtToday.getDate();
        sDate += iYear;
        sDate += "-" + (iMonth < 10 ? "0" + iMonth : iMonth);
        //如果刚好是选择到月份，则直接返回月份就够了
        if (curType !== this.enums.dateType.month) {
            sDate += "-" + (iDay < 10 ? "0" + iDay : iDay);
            if (curType === this.enums.dateType.second) {
                if (sDate != "") sDate += " ";
                if (this.data.curSelDate != null && !isNaN(this.data.curSelDate)) {
                    iVal = this.data.curSelDate.getHours();
                    sDate += iVal < 10 ? "0" + iVal : iVal;
                    iVal = this.data.curSelDate.getMinutes();
                    sDate += ":" + (iVal < 10 ? "0" + iVal : iVal);
                    iVal = this.data.curSelDate.getSeconds();
                    sDate += ":" + (iVal < 10 ? "0" + iVal : iVal);
                }
                else {
                    sDate += "00:00:00";
                }
            }
        }
        el.value = sDate;
        el.focus();
        if (el.onchange) el.onchange();
    }
    this.hide();
};

//点击今天
DateTimePanel.panelToday = function () {
    var el = this.data.curEl;
    if (el != null) {
        var dtToday = new Date();
        var sDate = "";

        //年月
        var iMonth = dtToday.getMonth() + 1;
        sDate += dtToday.getFullYear() + "-" + (iMonth < 10 ? "0" + iMonth : iMonth);
        if (this.data.curDateType !== this.enums.dateType.month) {
            sDate += "-" + dtToday.getDate();
            if (this.data.curDateType !== this.enums.dateType.date) {
                if (sDate != "") sDate += " ";
                var iVal;
                iVal = dtToday.getHours();
                sDate += iVal < 10 ? "0" + iVal : iVal;
                iVal = dtToday.getMinutes();
                sDate += ":" + (iVal < 10 ? "0" + iVal : iVal);
                iVal = dtToday.getSeconds();
                sDate += ":" + (iVal < 10 ? "0" + iVal : iVal);
            }
        }

        el.value = sDate;
        el.focus();
    }
    this.hide();
};
//点击“取消”
DateTimePanel.panelClose = function () {
    this.hide();
};

//Html模板
DateTimePanel.htmlTemplate = {
    //年月日的头部
    yyyyMMddHeader: "<tr><td id='PartDate' align='center' style='width:100%;height:20px;border-bottom:1 solid #E0E0E0;'>" +
 	                "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_YEAR + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	                "<a href='#' id='PartY' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_YEAR + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;width:50px;text-align:center;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>0000年</a>" +
 	                "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_YEAR + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a> " +
 	                "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_MON + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	                "<a href='#' id='PartM' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_MON + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>00月</a>" +
 	                "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_MON + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a> " +
 	                "<a href='#' id='PartD_L' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_DAY + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	                "<a href='#' id='PartD' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_DAY + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>00日</a>" +
 	                "<a href='#' id='PartD_R' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_DAY + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a>" +
 	                "</td></tr>",
   //时分秒的头部
   HHmmssHeader: "<tr><td id='PartTime' align='center' style='width:100%;height:20px;'>" +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_HOUR + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	             "<a href='#' id='PartH' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_HOUR + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;width:50px;text-align:center;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>00时</a>" +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_HOUR + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a> " +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_MINU + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	             "<a href='#' id='PartN' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_MINU + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;width:auto;text-align:center;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>00分</a>" +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_MINU + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a> " +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_SEC + "\",true);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>3</a>" +
 	             "<a href='#' id='PartS' onclick='parent.DateTimePanel.partClick(\"" + DateTimePanel.enums.PT.PT_SEC + "\")' style='border:1 solid #52A3E2;font-size:10pt;color:#ffffff;font-weight:bold;' bcr='#52A3E2' onmouseover='parent.DateTimePanel.hilightObj(this,1)' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>00秒</a>" +
 	             "<a href='#' onclick='parent.DateTimePanel.partArraw(\"" + DateTimePanel.enums.PT.PT_SEC + "\",false);' style='font-family:Marlett;font-size:9pt;color:#ffffff;border:1 solid #52A3E2;text-decoration:none;' onmouseover='parent.DateTimePanel.hilightObj(this,1)' bcr='#52A3E2' onmouseout='parent.DateTimePanel.hilightObj(this,0)'>4</a>" +
 	             "</td></tr>"
};